package com.kaibes.orm.core.listener;

import java.util.HashMap;
import java.util.Map;

public interface BaseListener {
    Map<Object, ThreadLocal<Object>> map = new HashMap<Object, ThreadLocal<Object>>();
    default boolean isWorking() {
        ThreadLocal<Object> threadLocal = map.get(this);
        if (threadLocal == null) {
            return true;
        }
        return threadLocal.get()==null;
    }
    default void pause() {
        ThreadLocal<Object> threadLocal = map.get(this);
        if (threadLocal == null) {
            threadLocal = new ThreadLocal<>();
            map.put(this, threadLocal);
        }
        threadLocal.set(this);
    }
    default void restart() {
        ThreadLocal<Object> threadLocal = map.get(this);
        if (threadLocal != null) {
            threadLocal.set(null);
        }
    }
    
}
